/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package VIEW;

import BEANS.ComboItem;
import CONTROLLERS.SecHandTradeInController;
import java.awt.event.KeyEvent;
import javax.swing.JComboBox;
import javax.swing.JTable;

/**
 *
 * @author weak_2030
 */
public class ViewSecondHandList extends javax.swing.JPanel {
    static SecHandTradeInController tradeInController;
    /**
     * Creates new form ViewSecondHandList
     */
    public ViewSecondHandList() {
        initComponents();
        tradeInController = new SecHandTradeInController(secondHandListTable, categoryFilterComboBox, clear, secondHandTableSearchInput);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        clear = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        secondHandListTable = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        categoryFilterComboBox = new javax.swing.JComboBox();
        secondHandTableSearchInput = new javax.swing.JTextField();
        jButton5 = new javax.swing.JButton();

        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        clear.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/xmark.png"))); // NOI18N
        clear.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clearMouseClicked(evt);
            }
        });
        add(clear, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 70, -1, 26));
        clear.setVisible(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("View SecondHand List");
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 11, 980, -1));

        secondHandListTable.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        secondHandListTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "SecondHand ID", "Product Name", "Description", "Type"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        secondHandListTable.setRowHeight(20);
        jScrollPane1.setViewportView(secondHandListTable);

        add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 110, 1010, 382));

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel3.setText("Category:");
        add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(810, 70, -1, 20));

        categoryFilterComboBox.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        categoryFilterComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        categoryFilterComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                categoryFilterComboBoxActionPerformed(evt);
            }
        });
        add(categoryFilterComboBox, new org.netbeans.lib.awtextra.AbsoluteConstraints(880, 70, 170, -1));

        secondHandTableSearchInput.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        secondHandTableSearchInput.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                secondHandTableSearchInputKeyPressed(evt);
            }
        });
        add(secondHandTableSearchInput, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 70, 300, -1));

        jButton5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton5.setText("Search");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 70, -1, -1));
    }// </editor-fold>//GEN-END:initComponents

    private void secondHandTableSearchInputKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_secondHandTableSearchInputKeyPressed
        if (evt.getKeyCode()== KeyEvent.VK_ENTER)
        {
            jButton5.doClick();
        }
    }//GEN-LAST:event_secondHandTableSearchInputKeyPressed

    private void clearMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clearMouseClicked
        tradeInController.clearSearch();
    }//GEN-LAST:event_clearMouseClicked

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        tradeInController.searchProduct();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void categoryFilterComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_categoryFilterComboBoxActionPerformed
        tradeInController.filterProducts();
    }//GEN-LAST:event_categoryFilterComboBoxActionPerformed

    public static JComboBox<ComboItem> getCategoryComboBox(){
        return categoryFilterComboBox;
    }
    
    public static JTable getSecondHandListTable(){
        return secondHandListTable;
    }
    
    public static void updateSecondHandListTable(){
        tradeInController.updateSecondHandTable();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private static javax.swing.JComboBox categoryFilterComboBox;
    private javax.swing.JLabel clear;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private static javax.swing.JTable secondHandListTable;
    private javax.swing.JTextField secondHandTableSearchInput;
    // End of variables declaration//GEN-END:variables
}
